#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    InitMainWidget();
    InitTabWidget();
    InitConnects();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::InitMainWidget()
{
    ui->tabWidget->setCurrentIndex(0);
    m_pRightMenu = new RightMenu();
    m_pBottomMenu = new PlayBottomMenu();
    m_pVLayout = new QVBoxLayout();
    m_pHLayout =new QHBoxLayout();
    m_pHLayout->addWidget(m_pRightMenu);
    m_pHLayout->addWidget(ui->tabWidget);
    m_pVLayout->addLayout(m_pHLayout);
    m_pVLayout->addWidget(m_pBottomMenu);
    this->centralWidget()->setLayout(m_pVLayout);
}

void MainWindow::InitTabWidget()
{
    m_pFindMusiclWidget = new TabWidget(ui->tabFindMusic);
    ui->verticalLayout0->addWidget(m_pFindMusiclWidget);

    m_pVideoWidget = new VideoWidget(ui->tabVideo);
    ui->verticalLayout1->addWidget(m_pVideoWidget);

    m_pFriendWidget = new FriendWidget(ui->tabFriend);
    ui->verticalLayout2->addWidget(m_pFriendWidget);

    m_pStreamingWidget = new StreamingWidget(ui->tabStreaming);
    ui->verticalLayout3->addWidget(m_pStreamingWidget);

    m_pPrivateFmWidget = new  PrivateFmWidget(ui->tabFM);
    ui->verticalLayout4->addWidget(m_pPrivateFmWidget);

    m_pLocalMusicWidget = new LocalMusicWidget(ui->tabLocalMusic);
    ui->verticalLayout5->addWidget(m_pLocalMusicWidget);

    m_pDownLoadMgrWidget = new DownLoadMgrWiget(ui->tabDownLoad);
    ui->verticalLayout6->addWidget(m_pDownLoadMgrWidget);

    m_pStorageMusicWidget = new StorageMusicWidget(ui->tabStorage);
    ui->verticalLayout7->addWidget(m_pStorageMusicWidget);

    m_pMyRadioWidget = new MyRadioWidget(ui->tabRadio);
    ui->verticalLayout8->addWidget(m_pMyRadioWidget);

    m_pMyCollectWidget = new MyCollectWidget(ui->tabCollect);
    ui->verticalLayout9->addWidget(m_pMyCollectWidget);
};

void MainWindow::InitConnects()
{
    connect(m_pRightMenu,&RightMenu::ClickRightType,this,&MainWindow::CutRightWidget);
    connect(m_pBottomMenu,&PlayBottomMenu::SendStart,m_pLocalMusicWidget,&LocalMusicWidget::SetPlayerStart);
    connect(m_pLocalMusicWidget,&LocalMusicWidget::SendStart,m_pBottomMenu,&PlayBottomMenu::Play_Slot);
    connect(m_pBottomMenu,&PlayBottomMenu::SendPause,m_pLocalMusicWidget,&LocalMusicWidget::SetPlayerPause);
    connect(m_pBottomMenu,&PlayBottomMenu::CurrentVolume,m_pLocalMusicWidget,&LocalMusicWidget::SetPlayerVolume);
    connect(m_pBottomMenu,&PlayBottomMenu::CurrentSpeed,m_pLocalMusicWidget,&LocalMusicWidget::SetPositionSpeed);
    connect(m_pLocalMusicWidget,&LocalMusicWidget::SendCurrentPlayerTime,m_pBottomMenu,&PlayBottomMenu::SetCurrentTime);
    connect(m_pLocalMusicWidget,&LocalMusicWidget::SendProgressMaximun,m_pBottomMenu,&PlayBottomMenu::SetProgressMaxValue);
    connect(m_pLocalMusicWidget,&LocalMusicWidget::SendCurrentProgressValue,m_pBottomMenu,&PlayBottomMenu::SetCurrentProgressValue);
}

void MainWindow::CutRightWidget(RightType RightMenuType)
{
    switch (RightMenuType)
    {
    case FindMusic:
        ui->tabWidget->setCurrentIndex(0);
        break;
    case Video:
        ui->tabWidget->setCurrentIndex(1);
        break;
    case Friend:
        ui->tabWidget->setCurrentIndex(2);
        break;
    case Streaming:
        ui->tabWidget->setCurrentIndex(3);
        break;
    case FM:
        ui->tabWidget->setCurrentIndex(4);
        break;
    case LocalMusic:
        ui->tabWidget->setCurrentIndex(5);
        break;
    case DownLoad:
        ui->tabWidget->setCurrentIndex(6);
        break;
    case Storage:
        ui->tabWidget->setCurrentIndex(7);
        break;
    case Radio:
        ui->tabWidget->setCurrentIndex(8);
        break;
    case Collect:
        ui->tabWidget->setCurrentIndex(9);
        break;
    case LoveMusic:
        ui->tabWidget->setCurrentIndex(10);
        break;
    case NewMusic:
        ui->tabWidget->setCurrentIndex(11);
        break;
    default:
        qDebug()<<"none select Type";
        break;
    }
}




